﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Xml.Linq;
using System.Windows.Resources;

namespace Sanctuary.Core.Dialog
{
    public class GameDialog
    {
        public const string FILE_NAME = "DialogDefinition.xml";
        private static StreamResourceInfo zipInfo;

        public GameDialog(XDocument document, StreamResourceInfo zip)
        {
            zipInfo = zip;

            foreach (XElement item in document.Descendants("Scene"))
            {
                DialogScene ds = new DialogScene()
                {
                    Name = item.Attribute("Name").Value,
                };
                foreach (XElement action in item.Descendants())
                {
                    ds.AddAction(GetAction(action));
                }
                scenes.Add(ds.Name, ds);
            }
        }

        private IDialogAction GetAction(XElement element)
        {
            IDialogAction action = null;
            switch (element.Name.LocalName)
            {
                case "EnterImage" :
                    action = new DialogImageEnterAction();
                    break;
                case "ExitImage" :
                    action = new DialogImageExitAction();
                    break;
                case "Sound" :
                    action = new DialogSoundAction();
                    break;
                case "Text" :
                    action = new DialogTextAction();
                    break;
                default:
                    break;
            }
            action.LoadFromXElement(element);
            return action;
        }

        private Dictionary<string, DialogScene> scenes = new Dictionary<string, DialogScene>();

        public DialogScene this[string sceneName]
        {
            get
            {
                if (!scenes.ContainsKey(sceneName))
                {
                    throw new GameContentException("Scene: " + sceneName + " not found.");
                }
                return scenes[sceneName];
            }
        }
    }
}
